package com.lizongbo.seotijian.rules.whois.domainhandlers;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import com.lizongbo.seotijian.rules.whois.DomainHandler;
import com.lizongbo.seotijian.rules.whois.WhoisClient;
import com.lizongbo.seotijian.util.HttpUtil;

public class ARDomainHandler implements DomainHandler {
	@Override
	public String getTld() {
		return ".ar";
	}

	@Override
	public String getWhoisInfo(String domain) {
		String urlStr = "http://www.nic.ar/consdom.html";
		String query = "nombre=google&dominio=.com.ar";
		String ss[] = new String[] { ".com.ar", ".gov.ar", ".int.ar",
				".mil.ar", ".net.ar", ".org.ar", ".tur.ar" };
		for (int i = 0; i < ss.length; i++) {
			if (domain.endsWith(ss[i])) {
				query = "nombre=" + domain.substring(0, domain.indexOf(ss[i]))
						+ "&dominio=" + ss[i];
			}
		}
		String txt = "";
		try {
			txt = WhoisClient.trimEmptyLine(
					WhoisClient.html2txt(HttpUtil.httpPost(urlStr, query,
							"http://www.nic.ar/consdom.html"))).replace(":\n",
					":");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return txt;
	}
}